package com.wkq.main.application


import android.content.Context
import com.scwang.smart.refresh.footer.ClassicsFooter
import com.scwang.smart.refresh.header.MaterialHeader
import com.scwang.smart.refresh.layout.SmartRefreshLayout
import com.scwang.smart.refresh.layout.api.RefreshFooter
import com.scwang.smart.refresh.layout.api.RefreshHeader
import com.scwang.smart.refresh.layout.api.RefreshLayout
import com.scwang.smart.refresh.layout.listener.DefaultRefreshFooterCreator
import com.scwang.smart.refresh.layout.listener.DefaultRefreshHeaderCreator
import com.tencent.bugly.crashreport.CrashReport
import com.tencent.mmkv.MMKV


import com.wkq.main.R
import okhttp3.OkHttpClient
import java.util.logging.Level
import java.util.logging.Logger


/**
 *
 *@Author: wkq
 *
 *@Time: 2025/4/8 15:39
 *
 *@Desc:
 */
class MyAppApplication : BaseApplication() {

    override fun onCreate() {
        super.onCreate()
        // 多进程会触发多次，这里判断当前进程名是否是本进程名
        if (this.packageName.equals(getProcessName(this))){
            initLib()
            initSmartRefresh()
            Logger.getLogger(OkHttpClient::class.java.name).level = Level.FINE
            CrashReport.initCrashReport(getApplicationContext(), "bffe339085", true);
        }

    }




    private fun initSmartRefresh() {
        //设置全局的Header构建器
        SmartRefreshLayout.setDefaultRefreshHeaderCreator(object : DefaultRefreshHeaderCreator {
            override fun createRefreshHeader(
                context: Context, layout: RefreshLayout
            ): RefreshHeader {

                return MaterialHeader(context).setColorSchemeResources(R.color.purple_200, R.color.purple_500, R.color.purple_700)

            //.setTimeFormat(new DynamicTimeFormat("更新于 %s"));//指定为经典Header，默认是 贝塞尔雷达Header
            }
        })

        //设置全局的Footer构建器
        SmartRefreshLayout.setDefaultRefreshFooterCreator(object : DefaultRefreshFooterCreator {
            override fun createRefreshFooter(
                context: Context,
                layout: RefreshLayout
            ): RefreshFooter {
                //指定为经典Footer，默认是 BallPulseFooter
                return ClassicsFooter(context).setDrawableSize(20f)
            }
        })
    }

    /**
     * 初始化三方
     */
    private fun initLib() {
        MMKV.initialize(this)
        initNet()

    }


}